<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2021/8/31
  Time: 9:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="main" style="width: 600px;height:400px;"></div>

    <script src="<%=request.getContextPath()%>/static/echarts.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="<%=request.getContextPath()%>/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        $.post(
            '${pageContext.request.contextPath}/banji?method=selectBanjiCount',
            function(jsonObj) {
                console.log(jsonObj);
                // [{value: 2, name: "java1807"}, {…}, {…}]
                var xArray = new Array();
                var yArray = new Array();
                $(jsonObj).each(function (){
                    // this  {value: 2, name: "java1807"}
                    xArray.push(this.name);
                    yArray.push(this.value);
                })
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: '班级人数统计'
                    },
                    tooltip: {},
                    legend: {
                        data:['班级']
                    },
                    xAxis: {
                        data: xArray
                    },
                    yAxis: {},
                    series: [{
                        name: '人数',
                        type: 'bar',
                        data: yArray
                    }]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            },
            'json'
        );

    </script>
</body>
</html>
